package edu.dlust.trading_platform.DataBase;

import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Filters;

import org.bson.Document;
import org.bson.conversions.Bson;
import org.json.JSONArray;

import java.util.ArrayList;
import java.util.List;

import edu.dlust.trading_platform.DataBean.hostname;

public class MongoDB {
    public void insert(String id,String msg,String uid,String UName,String time){
        MongoClient mongoClient = MongoClients.create("mongodb://frp.lsakura.top:8003");
        MongoDatabase database = mongoClient.getDatabase("android");
        MongoCollection<Document> collection = database.getCollection("message");

        // 创建文档
        Document doc = new Document("GoodsId", id)
                .append("message", msg)
                .append("Uid", uid)
                .append("UName", UName)
                .append("time", time);
        // 插入文档
        collection.insertOne(doc);
        //关闭连接
        mongoClient.close();
    }
}
